package entity.connector;

import entity.bean.Movie;
import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 *
 * @author 52571783
 */
public class MovieUploader {
    public static void addMovie(Movie movie) {
        try {
            Connection con = ConnectionProvider.getCon();
            PreparedStatement ps = con.prepareStatement(
                    "INSERT INTO movie (default_price,movie_name,director,cast,duration,categary,language,synopsis)"
                    + "VALUES (?,?,?,?,?,?,?,?)");
            ps.setInt(1, movie.getPrice());
            ps.setString(2, movie.getName());
            ps.setString(3, movie.getDirector());
            ps.setString(4, movie.getCast());
            ps.setInt(5, movie.getDuration());
            ps.setString(6, movie.getCategary());
            ps.setString(7, movie.getLanguage());
            ps.setString(8, movie.getSynopsis());
            ps.executeUpdate();
            ps.close();
        } catch (Exception e) {
        }
    }
    
    public static void editMovie(Movie movie) {
        try {
            Connection con = ConnectionProvider.getCon();
            PreparedStatement ps = con.prepareStatement(
                    "UPDATE movie SET default_price = ?, movie_name = ?, director,cast = ?,"
                    + "duration = ?, categary = ?, language = ?, synopsis = ? WHERE movie_id = ?");
            ps.setInt(1, movie.getPrice());
            ps.setString(2, movie.getName());
            ps.setString(3, movie.getDirector());
            ps.setString(4, movie.getCast());
            ps.setInt(5, movie.getDuration());
            ps.setString(6, movie.getCategary());
            ps.setString(7, movie.getLanguage());
            ps.setString(8, movie.getSynopsis());
            ps.setInt(9, movie.getId());
            ps.executeUpdate();
            ps.close();
        } catch (Exception e) {
        }
    }
}
